package com.flxz.user.controller;

import com.flxz.common.core.controller.BaseController;
import com.flxz.common.core.domain.AjaxResult;
import com.flxz.user.domain.vo.ChartDataVO;
import com.flxz.user.service.IUserChartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;


/**
 * 用户图表统计Controller
 * 
 * @author flxz
 * @date 2024-01-15
 */
@RestController
@RequestMapping("/user/chart")
public class UserChartController extends BaseController
{
    @Autowired
    private IUserChartService userChartService;

    /**
     * 获取图表数据
     */
    @PreAuthorize("@ss.hasRole('common') or @ss.hasPermi('user:chart:query')")
    @GetMapping("/data")
    public AjaxResult getChartData(
            @RequestParam(required = false) String timeRange,
            @RequestParam(required = false) String startDate,
            @RequestParam(required = false) String endDate)
    {
        Long userId = getUserId();
        ChartDataVO chartData = userChartService.getChartData(userId, timeRange, startDate, endDate);
        return success(chartData);
    }

    /**
     * 导出图表数据
     */
    @PreAuthorize("@ss.hasRole('common') or @ss.hasPermi('user:chart:export')")
    @GetMapping("/export")
    public AjaxResult exportChartData(
            @RequestParam(required = false) String timeRange,
            @RequestParam(required = false) String startDate,
            @RequestParam(required = false) String endDate)
    {
        Long userId = getUserId();
        // 这里可以实现导出功能，暂时返回图表数据
        ChartDataVO chartData = userChartService.getChartData(userId, timeRange, startDate, endDate);
        return success(chartData);
    }

}
